/**
 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.library.slayer.service.http;

import com.library.slayer.model.Book;

import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.util.StringPool;

import java.util.Date;
import java.util.List;

/**
 * @author    Ahmed Hasan
 * @generated
 */
public class BookJSONSerializer {
	public static JSONObject toJSONObject(Book model) {
		JSONObject jsonObj = JSONFactoryUtil.createJSONObject();

		jsonObj.put("bookId", model.getBookId());
		jsonObj.put("bookTitle", model.getBookTitle());
		jsonObj.put("author", model.getAuthor());

		Date dateAdded = model.getDateAdded();

		String dateAddedJSON = StringPool.BLANK;

		if (dateAdded != null) {
			dateAddedJSON = String.valueOf(dateAdded.getTime());
		}

		jsonObj.put("dateAdded", dateAddedJSON);

		Date dateModified = model.getDateModified();

		String dateModifiedJSON = StringPool.BLANK;

		if (dateModified != null) {
			dateModifiedJSON = String.valueOf(dateModified.getTime());
		}

		jsonObj.put("dateModified", dateModifiedJSON);

		return jsonObj;
	}

	public static JSONArray toJSONArray(com.library.slayer.model.Book[] models) {
		JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

		for (Book model : models) {
			jsonArray.put(toJSONObject(model));
		}

		return jsonArray;
	}

	public static JSONArray toJSONArray(
		com.library.slayer.model.Book[][] models) {
		JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

		for (Book[] model : models) {
			jsonArray.put(toJSONArray(model));
		}

		return jsonArray;
	}

	public static JSONArray toJSONArray(
		List<com.library.slayer.model.Book> models) {
		JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

		for (Book model : models) {
			jsonArray.put(toJSONObject(model));
		}

		return jsonArray;
	}
}